import pandas as pd

import graphscope
from graphscope.framework.loader import Loader


def build_grid(
    acbus: pd.DataFrame,
    acline: pd.DataFrame,
    acsw: pd.DataFrame,
    acload: pd.DataFrame,
    acsource: pd.DataFrame,
    storage: pd.DataFrame,
    photovoltaic: pd.DataFrame,
    vsc: pd.DataFrame,
    dcbus: pd.DataFrame,
    dcline: pd.DataFrame,
    dcsw: pd.DataFrame,
    dcload: pd.DataFrame,
):
    sess = graphscope.session(cluster_type="hosts", num_workers=1, mode="lazy")
    graph = (
        sess.g()
        .add_vertices(
            acbus,
            label="acbus",
            properties=["name", "kV"],
        )
        .add_vertices(
            acline,
            label="acline",
            properties=["name", "nphase", "parameter", "length", "unit"],
        )
        .add_vertices(
            acsw,
            label="acswitch",
            properties=["name", "nphase", "parameter"],
        )
        .add_vertices(
            acload,
            label="acload",
            properties=["name", "nphase", "P", "Punit", "Q", "Qunit"],
        )
        .add_vertices(
            acload,
            label="acsource",
            properties=["name", "nphase", "kV", "pu", "degree"],
        )
        .add_edges(
            acline,
            label="connect",
            src_label="acline",
            dst_label="acbus",
            properties=["cond1", "cond2"],
        )
    )
    graph = sess.run(graph)
    sess.close()
